<template>
    <div>
        <Header></Header>
        <div class="block">
            <el-timeline>
                <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
                    <el-card>
                        <router-link :to="{name:'BlogDetail',params:{blogId:blog.id}}">
                            <h4>{{blog.title}}</h4>
                        </router-link>
                        <p>{{blog.description}}</p>
                    </el-card>
                </el-timeline-item>

            </el-timeline>
            <div>
                <el-pagination class="mcount"
                               background
                               layout="prev, pager, next"
                               :page-size="pageSize"
                               :current-page="current"
                               :total="total"
                               @current-change="page"
                >
                </el-pagination>
            </div>

        </div>
    </div>
</template>

<script>
    import Header from '../components/Header'

    export default {
        name: "Blogs",
        components: {Header},
        data() {
            return {
                blogs: {},
                total: 0,
                pageSize: 5,
                current: 1
            }
        },
        methods: {
            page(currentPage) {
                const _this = this
                _this.$axios.get('/blog/blogs?currentPage=' + currentPage).then(res => {
                    console.log(res)
                    _this.blogs = res.data.data.records
                    _this.total = res.data.data.total
                    _this.pageSize = res.data.data.size
                    _this.current = res.data.data.current
                })
            }
        },
        created() {
            this.page(1)
        }
    }
</script>

<style scoped>
    .mcount {
        text-align: center;
        margin: 0 auto;
        max-width: 60%;
    }
</style>